\ProvidesPackage{simplecv}

% Packages

\usepackage[cm]{fullpage}                   % Margins
\usepackage[hidelinks]{hyperref}            % Hyperlinks
\usepackage{titlesec}                       % Title formatting
\usepackage{subfiles}                       % File importing
\usepackage{multicol}                       % Multiple columns
\usepackage[usenames,dvipsnames]{xcolor}    % Coloring
\usepackage{enumitem}                       % List customization
\usepackage{lastpage}                       % Page numbering
\usepackage{fancyhdr}                       % Footers
\usepackage[russian,english]{babel}         % Language styles
\usepackage{graphicx}                       % Importing graphics
\usepackage[export]{adjustbox}              % Aligning margins

% % Chinese
% \usepackage{xeCJK}
% \setCJKmainfont{BabelStone Han}

% % Cyrillic/Russian
% \usepackage{hyphenat}
% \babelfont{rm}{Droid Sans}

% Styling
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\urlstyle{same}
\raggedbottom
\raggedright
\setlength{\tabcolsep}{0in}

% Quotes
\usepackage[autostyle,english=american]{csquotes}
\MakeOuterQuote{"}

% Hyperlinks
% \newcommand{\link}[2]{\href{#1}{\underline{\smash{#2}}}}
\newcommand{\link}[2]{\href{#1}{#2}}

% Define colors
\definecolor{color-text}{gray}{0.10}    % light black
\definecolor{color-detail}{gray}{0.40}  % dark gray
\colorlet{color-title}{\theme}          % black

% Set text color
\makeatletter
\newcommand{\globalcolor}[1]{\color{#1}\global\let\default@color\current@color}
\makeatother
\AtBeginDocument{\globalcolor{color-text}}

% Shorthand
\newcommand{\github}[1]{\href{https://github.com/#1/}{github.com/#1}}
\newcommand{\email}[1]{\href{mailto:#1}{#1}}
\newcommand{\website}[1]{\href{https://#1/}{#1}}
\newcommand{\linkedin}[1]{\href{https://www.linkedin.com/in/#1/}{#1}}

% Dummy environment
\newenvironment*{dummyenv}{}{}

% Inline heading
\newcommand{\headinginline}[2]{
    \begin{minipage}[t]{0.60\textwidth}
    \vspace*{\fill}
    \Huge \textcolor{black}{#1}
    \end{minipage}
    \begin{minipage}[t]{0.39\textwidth}
    \begin{flushright}
    #2
    \end{flushright}
    \end{minipage}
}

% Photo heading
\newcommand{\headingphoto}[3]{
    \begin{minipage}[t]{0.60\textwidth}
    \begin{dummyenv}
    \vspace*{\fill}
    \Huge \textcolor{color-title}{#1}
    \end{dummyenv}
    \vspace{5mm}\\
    #2
    \end{minipage}
    \begin{minipage}[t]{0.35\textwidth}
    \begin{flushright}
    \includegraphics[width=.5\linewidth,valign=t]{#3}
    \end{flushright}
    \end{minipage}
}

% Two-columns
\newcommand{\sidebyside}[2]{
    \begin{multicols}{2}
    #1 \columnbreak
    #2 \end{multicols}
}

% Section titles
%\titleformat{\section}{
%    \scshape\raggedright\Large\color{color-title}}{}{0em}{}[\color{color-title}\titlerule
%    \vspace{-\smallskipamount}]
\titleformat{\section}{
	\raggedright\LARGE\color{color-title}}{}{0em}{}[\color{color-title}\titlerule
\vspace{-\smallskipamount}]

% Footer
%\fancyhead[C]{\color{color-detail} 234}

%\fancyfoot[C]{\color{color-detail} Chen-Zhu Xie\ \textendash\ CV}
%\fancyfoot[C]{\color{color-detail} Chenzhu Xie $|$ 谢尘竹}
%\fancyfoot[C]{\color{color-detail} Chenzhu Xie}
%\fancyhead[C]{\color{color-detail} Chenzhu Xie}
\fancyhead[C]{\color{color-detail} \href{https://github.com/ChenZhu-Xie/CV_xcz}{Curriculum Vitae}}

\def\mydate{\leavevmode\hbox{\the\year-\twodigits\month-\twodigits\day}}
\def\twodigits#1{\ifnum#1<10 0\fi\the#1}

%\fancyfoot[L]{\color{color-detail} Last updated: \mydate}
%\fancyfoot[L]{\color{color-detail} CV\_\mydate}
%\fancyfoot[L]{\color{color-detail} CV $|$ \mydate}
%\fancyhead[L]{\color{color-detail} CV $|$ \mydate}
%\fancyhead[L]{\rule[-2ex]{0pt}{2ex} \color{color-detail} CV $|$ \mydate}
%\fancyhead[L]{\vspace*{5mm} \color{color-detail} CV $|$ \mydate}
%\fancyhead[L]{\color{color-detail} CV $|$ \mydate \newline}
%\fancyhead[L]{\color{color-detail} CV $|$ \mydate \vskip 1cm}
%{\vspace*{1mm} \fancyhead[L]{\color{color-detail} CV $|$ \mydate}}
%\fancyhead[L]{\color{color-detail} CV $|$ \mydate}
\fancyhead[L]{\color{color-detail} Chenzhu Xie}

%\fancyfoot[R]{\color{color-detail} Page \thepage \hspace{1pt} of \hspace{0.4pt} \pageref{LastPage}}
%\fancyfoot[R]{\color{color-detail} Page \thepage$/$\pageref{LastPage}}
%\fancyhead[R]{\color{color-detail} Page \thepage$/$\pageref{LastPage}}
\fancyhead[R]{\color{color-detail} \mydate}

\fancyfoot[R]{\color{color-detail} Page \thepage$/$\pageref{LastPage}}

\fancypagestyle{noheader}{%
	\fancyhead{}%
}


% Lists
\newcommand{\outerlist}[1]{
    \begin{itemize}[leftmargin=*] #1 \end{itemize}}
\newcommand{\denseouterlist}[1]{
    \begin{itemize}[leftmargin=*,itemsep=0pt] #1 \end{itemize}}
\newcommand{\innerlist}[1]{
    \begin{itemize}[topsep=0pt] #1 \end{itemize}}
\newcommand{\orderedouterlist}[1]{
    \begin{enumerate}[leftmargin=*] #1 \end{enumerate}}

% List items
\newcommand{\entry}[1]{\item\small{#1}}
\newcommand{\entryextra}[1]{\textcolor{color-detail}{\entry{#1}}}
\newcommand{\entrylabeled}[2][]{\item[#1]\small{#2}}

\newcommand{\entrymid}[4][]{
    \item[#1] \small{#2} \hfill \small{#3}
    \vspace{-\smallskipamount} \item[]\small{\textit{#4}}}

\newcommand{\entrybig}[5][]{\item[#1]
    \begin{tabular*}{0.97\textwidth}{l@{\extracolsep{\fill}}r}
    #2 & #3 \\ {\small#4} & {\small #5} \\ \end{tabular*}}

% Fill year
\newcommand{\fillyear}[1]{\phantom{#1}}

% Make author name bold: https://tex.stackexchange.com/a/327046
\newcommand*{\boldname}[3]{%
  \def\lastname{#1}%
  \def\firstname{#2}%
  \def\firstinit{#3}}
\boldname{}{}{}

\renewcommand{\mkbibnamegiven}[1]{%
  \ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
  {\mkbibbold{#1}}{#1}%
}

\renewcommand{\mkbibnamefamily}[1]{%
  \ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} }
  {\mkbibbold{#1}}{#1}%
}